package controllers

import (
	"github.com/astaxie/beego"
	"strconv"
	"goblog/models/dao"
)

type CategoryController struct {
	beego.Controller
}

func (this *CategoryController) Get() {
	id, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))
	page, _ := this.GetInt("page", 1)

	categoryDao := new(dao.CategoryDao)
	articleDao := new(dao.ArticleDao)

	term := new(dao.ArticleTerm)
	term.Size = 10
	term.Page = page
	term.Status = dao.DISPLAY
	cate := categoryDao.Get(id)
	switch cate.Level {
	case 1:
		term.FirstId = cate.Id
	case 2:
		term.SecondId = cate.Id
	case 3:
		term.ThirdId = cate.Id

	}
	articleDao.Find(term)
	this.Data["page"] = term
	this.Data["catId"] = id
	this.Data["next"] = term.Page + 1
	this.Data["pre"] = term.Page - 1
	seoDao := new(dao.SeoDao)
	seo := seoDao.Get("Home", 0)
	this.Data["seo"] = seo
	this.Layout = "layout/layout.html"
	this.TplName = "category.html"

	SetCatList(this.StartSession(), this.Data)
}
